/**
 * 
 */
package ua.kpi.javatrainee6.model.departments;

import java.util.Arrays;
import java.util.Iterator;

import ua.kpi.javatrainee6.model.curriculum.Subjects;
import ua.kpi.javatrainee6.model.people.*;


/**
 * Encapsulating logic for work with with array of groups
 */
public class Groups implements Iterable<Group> {
	
	private static final int GROUPS_NUMBER = 1;
	private static final int STUDENTS_NUMBER_IN_GROUP = 6;
	private Group[] groups;
	
	/**
	 * creating groups and filling them with students
	 * The same as for professors filling, must be changed with real data
	 */
	public Groups(University univer, UniversityAdministrator admin) {
		groups = new Group[GROUPS_NUMBER];
		for (int i = 0; i < GROUPS_NUMBER; i++) {
			groups[i] = new Group(univer);
			Student[] students = new Student[STUDENTS_NUMBER_IN_GROUP];
			for (int j = 0; j < STUDENTS_NUMBER_IN_GROUP; j++) {
				students[j] = new Student(groups[i], admin);
			}
			groups[i].setStudents(students);
		}
	}
	
	private Groups(Group[] groups) {
		this.groups = groups;
	}
	
	/**
	 * Adding subjects for all groups,
	 * All subjects are now added for all groups, real data will also change situation
	 */
	public void add(Subjects subjects) {
		for (int i = 0; i < GROUPS_NUMBER; i++) {
			groups[i].setSubjects(subjects);
		}
	}
	
	public Group get(int index) {
		return groups[index];
	}
	
	public Iterator<Group> iterator() {
		return Arrays.asList(groups).iterator();
	}
	
	public int size() {
		return groups.length;
	}
	
	public Groups copy() {
		return new Groups(groups.clone());
	}
	
	public void print() {
		for (Group group : this) {
			System.out.println(group);
		}
	}
}
